package com.example.demoeasyexcelboot.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.example.demoeasyexcelboot.dto.UserDto;
import com.example.demoeasyexcelboot.excel.ExcelCellBo;

import java.util.List;
import java.util.Map;

/**
 * @author: FSL
 * @date: 2023/4/13
 * @description: 简单Excel导入校验
 */
public class SimpleDataValidListener<E> extends AbstractDataValidListener<E>{

    public SimpleDataValidListener(List headList) {
        super(headList, true);
    }
    public SimpleDataValidListener(Class<E> c){
        super(c,true);
    }
    @Override
    public void invoke(E o, AnalysisContext analysisContext) {
        if (o instanceof UserDto){
            UserDto userDto = (UserDto)o;
            System.out.println(userDto);
        }
        Map<String, ExcelCellBo> propertyNameMap = getPropertyNameMap(true, analysisContext);
        if (validate(o,propertyNameMap)){
            dataList.add(o);
        }
    }
}
